Implement support for ASTC compressed KTX textures#37
Implement support for ASTC compressed KTX textures#37Erik-White wants to merge 6 commits intoSixLabors:mainfrom
Conversation
| *.dds filter=lfs diff=lfs merge=lfs -text | ||
| *.ktx filter=lfs diff=lfs merge=lfs -text | ||
| *.ktx2 filter=lfs diff=lfs merge=lfs -text | ||
| *.astc filter=lfs diff=lfs merge=lfs -text |
There was a problem hiding this comment.
This keeps getting overwritten by a target that copies gitattributes from the shared project, so I will need to update it there as well
| return (ulong)FloatHelper.PackFloatToFloat16(vector.X) | ||
| | ((ulong)FloatHelper.PackFloatToFloat16(vector.Y) << 16) | ||
| | ((ulong)FloatHelper.PackFloatToFloat16(vector.Z) << 32) | ||
| | ((ulong)FloatHelper.PackFloatToFloat16(vector.W) << 48); |
There was a problem hiding this comment.
Casting to unit could result in an overflow when shifting. Widening to a long allows for correct shifting without overflow
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> |
There was a problem hiding this comment.
AstcEncoderCSharp only supports .NET10 so I kept this in a separate test project. It is very useful to be able to compare output directly with the ARM implementation.
| using SixLabors.ImageSharp.Textures.Tests.TestUtilities.Attributes; | ||
| using SixLabors.ImageSharp.Textures.Tests.TestUtilities.TextureProviders; | ||
|
|
||
| namespace SixLabors.ImageSharp.Textures.Tests.Formats.Astc.HDR; |
There was a problem hiding this comment.
I wasn't quite sure whether to use uppercase or title case (HDR vs Hdr) for this namespace. Title case is mostly used elsewhere, but there are some excepts like IO
|
@brianpopow Hopefully this is now structured in a way that fits well with rest of the project. I'm afraid that it ends up being a massive PR though, mainly due to the complexity of ASTC. |
Prerequisites
Description
Adds support for decoding ASTC compressed KTX and KTX2 textures, including both LDR and HDR modes. Implementing an ASTC decoder was a major challenge, but I was able to base a lot of it on existing C++ implementations from ARM and Khronos.
ASTC is very complex, with different combinations of modes, block sizes and partitions, so I'm afraid that the diff is very large.
I have added tests that compare the output vs the ARM C++ implementation to ensure correctness (see ImageSharp.Textures.Astc.Reference.Tests), however this had to be a separate test project because the C# bindings wrapper (AstcEncoderCSharp) only supports .NET10.
Decoding speed compares favorably to the reference decoder, but I couldn't include those benchmarks here, again due to the .NET10 issue. You can find some comparison benchmarks in my separate implementation: https://github.com/Erik-White/AstcSharp
KTX1 has support for ASTC, but I couldn't find a tool to create test images and had a difficult time sourcing test data. So the tests are quite limited for v1, but much better for KTX2.
Limitations
Test data
Everything used is either created by myself, or sourced from
https://github.com/KhronosGroup/KTX-Software (Apache 2.0 license)
https://github.com/KhronosGroup/KTX-Software-CTS (Apache 2.0 license)
https://github.com/ARM-software/astc-encoder (Apache-2.0 license)